package com.qianfeng.controller;

import com.qianfeng.dto.Message;
import com.qianfeng.dto.Result;
import com.qianfeng.entity.DayStudentChange;
import com.qianfeng.entity.HomeMonthChange;
import com.qianfeng.service.StudentService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

@Controller
public class HomeWeekController {
    @Autowired
    private StudentService studentService;
    /**
     * 统计每天人员增长
     * @return
     */
    @RequiresRoles(value = {"teacher","manager"},logical= Logical.OR)
    @CrossOrigin
    @ResponseBody
    @RequestMapping(value = "/getHomeWeek")
    public Result getHomeWeek() throws ParseException {
        Result result = new Result();
        result.setMessage(new Message());
        List<DayStudentChange> changeDayStudent = studentService.getChangeDayStudent(new Date());
        result.setObj(changeDayStudent);
        return result;
    }


    /**
     * 统计前六个月的增长趋势
     * @return
     */
    @RequiresRoles(value = {"teacher","manager"},logical= Logical.OR)
    @CrossOrigin
    @ResponseBody
    @RequestMapping(value = "/getHomeMonth")
    public Result getHomeMonth() throws ParseException {
        Result result = new Result();
        HomeMonthChange homeMonthChange = studentService.getHomeMonthChange();
        result.setMessage(new Message());
        result.setObj(homeMonthChange);
        return result;
    }

}
